#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File    :   hash.py
@Time    :   2024-07-09 13:01:40
@Author  :   chakcy 
@Email   :   947105045@qq.com
@description   :   redis hash 操作
'''

from typing import Any, Dict

from redis.asyncio import Redis

class Hash:
    def __init__(self, redis: Redis):
        # 初始化 Redis 连接
        self.redis = redis
    async def get_value(self, key: str, field: str) -> str:
        """获取指定键和字段的值"""
        return await self.redis.hget(key, field)  # type: ignore
    async def set_value(self, key: str, field: str, value: str) -> Any:
        """设置指定键和字段的值"""
        return await self.redis.hset(key, field, value)  # type: ignore
    async def delete_value(self, key: str, field: str) -> Any: 
        """删除指定键和字段的值"""
        return await self.redis.hdel(key, field)  # type: ignore
    async def get_all_values(self, key: str) -> Dict[str, Any]:
        """获取指定键的所有字段和值"""
        return await self.redis.hgetall(key)  # type: ignore